﻿@using System.Web.Mvc
@using System.Web.Mvc.Ajax
@using System.Web.Mvc.Html
@using nanoCMS.Core
@using nanoCMS.Core.WebProviders.HtmlHelpers
@using nanoCMS.Core.WebProviders.HtmlHelpers.Pagination
@using nanoCMS.Forum.Config
@using nanoCMS.Forum.Resources
@using nanoCMS.Forum.WebUI.Models.ViewModels
@model ThreadDisplayVM 
@*

@{
    MvcHtmlString headerContent = new MvcHtmlString(Html.ActionLink("up", "Index", "Forum", new {forumID = Model.ParentForum.ForumID}, null) + " - " +
                                                    Model.Thread.Title);
    Html.RenderPartial("ForumHeader", new ForumHeaderVM() { Content = headerContent });
}
@if (Model.Thread.IsClosed)
{
    <div>@Html.ActionLink("Unlock", "ChangeLockThreadState", "Forum", new {threadID = Model.Thread.ThreadID}, null)</div>
} else
{
    <div>@Html.ActionLink("Lock", "ChangeLockThreadState", "Forum", new { threadID = Model.Thread.ThreadID }, null)</div>
    <div>@Html.ActionLink("Create reply", "CreatePost", "Forum", new { threadID = Model.Thread.ThreadID }, null)</div>
}

@{ Html.RenderPartial("PostDisplay", Model.ThreadPost); }
@foreach(var post in Model.ThreadPosts)
{
    Html.RenderPartial("PostDisplay", post); 
}

    @{
    PagerOptions pagerOptions = new PagerOptions()
    {
        PageIndexParameterName = "page"
    };
}
@Html.Pager(Model.Thread.PostsCount, ForumConfig.PostsPerPage, Model.Page, "ShowThread", "Forum", 
    pagerOptions, "ForumDefault", new { }, null)

*@
<article class="article">
    <header class="page-title">
        <h2>
            @Translation.Forum > @Html.LinkInner(Model.ParentForum.Title, new { forumID = Model.ParentForum.ForumID, elementKey = ViewBag.ElementKey, action = "Index" }, null)</h2>
    </header>
    <!-- end page title -->
    <div class="separator">
    </div>
    <table class="forum">
        <tr>
            <th colspan="2">@Model.Thread.Title
            </th>
        </tr>
        @{ if (Model.Page == 1) { Html.RenderPartial("PostDisplay", Model.ThreadPost); } }
        @foreach (var post in Model.ThreadPosts)
        {
            Html.RenderPartial("PostDisplay", post);
        }
    </table>
    @if (SessionManagerBase.IsAuthenticated && !Model.Thread.IsClosed)
    {
        using (Ajax.BeginForm("SavePost", "Forum", new { area = "Forum" }, new AjaxOptions { OnSuccess = "SavePostComplete" }, new { }))
        {
        <input type="hidden" name="link" value="@ViewContext.RequestContext.RouteData.Values["link"]"/>
            <input type="hidden" name="elementKey" value="@ViewBag.ElementKey"/>
            <!-- WYSIWYG editor -->
            <input type="hidden" name="ThreadID" id="EditPostVM_Thread_ThreadID" value="@(Model.Thread.ThreadID)"/>
            <div class="widget">
                <div class="head">
                    <h5 class="iPencil">
                        @Translation.PostContent:</h5>
                </div>
                <textarea class="wysiwyg" rows="5" cols="" name="Content"></textarea>
            </div>
            <div class="footerForm">
                <input type="submit" class="greyishBtn submitForm" value="Pošalji odgovor">
            </div>
        }
    }
</article><!-- end #article -->


@Html.Pager(Model.Thread.PostsCount, ForumConfig.PostsPerPage, Model.Page, new PagerOptions(), new
{
    action = "ShowThread", elementKey = ViewBag.ElementKey, threadID = Model.Thread.ThreadID
})

<script type="text/javascript">
    function SavePostComplete(params) {
        ajaxFormSuccess(params);
    }
</script>